package com.spark.usermusicService.controller;


import com.spark.R;
import com.spark.usermusicService.entity.Playlist;
import com.spark.usermusicService.service.PlaylistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 歌单 前端控制器
 * </p>
 *
 * @author wzk
 * @since 2021-07-01
 */
@RestController
@RequestMapping("/usermusicService/playlist")
@CrossOrigin
public class PlaylistController {
    @Autowired
    private PlaylistService playlistService;
    @GetMapping("/user/{userId}")
    public R findAllByUserId(@PathVariable("userId") String userId) {
        List<Playlist> playlist = playlistService.getPlaylistByUserId(userId);
        return R.ok().data("items", playlist);
    }

//    @GetMapping(value = "/user")
//    public R findAllByUserId(@RequestParam("userId") String userId) {
//        List<Playlist> playlist = playlistService.getPlaylistByUserId(userId);
//        return R.ok().data("items", playlist);
//    }

    @GetMapping("/{playlistId}")
    public R findByPlayListId(@PathVariable("playlistId") String playlistId) {
        Playlist playlist = playlistService.getById(playlistId);
        return R.ok().data("items", playlist);
    }

    @GetMapping("/delete/{playlistId}")
    public R deleteByPlayListId(@PathVariable("playlistId") String playlistId) {
        boolean removeById = playlistService.deleteById(playlistId);
        return R.ok();
    }

    @PostMapping("/update")
    public R updatePlayList(@RequestBody() Playlist playlist) {
        boolean b = playlistService.saveOrUpdate(playlist);
        return R.ok();
    }
}

